package com.example.link.mapper;

import com.example.link.entity.ShortLink;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author qwert
 * @version 1.0.0
 * @create 2025/8/17 16:00
 **/
@Mapper
public interface ShortLinkMapper {
    @Insert("""
INSERT INTO short_link (short_url, original_url, favicon, name, user_id, group_id, domain_id, limit_type, expiry_date, validity_type, visit_limit,
 create_time, update_time, operator_id, is_delete) 
 VALUES (#{shortUrl}, #{originalUrl}, #{favicon}, #{name}, #{userId}, #{groupId}, #{domainId}, #{limitType}, #{expiryDate}, #{validityType}, #{visitLimit},
  now(), now(), null, 0);
""")
    void insertShortLink(ShortLink shortLink);

    @Select("""
select * from short_link where group_id = #{groupId} order by update_time desc;
""")
    List<ShortLink> queryLinkCountByGroupId(String groupId);

    @Select("""
select * from short_link where short_url = #{shortUrl};
""")
    ShortLink queryLinkByShortUrl(@Param("shortUrl") String shortUrl);

    @Select("""
select short_url from short_link where user_id = #{userId};
""")
    List<String> queryLinkCountByUserId(String userId);
}
